<template>
  <p-table
    class="table-list-container"
    row-key="id"
    :columns="columns"
    bordered
    v-bind="$attrs"
    v-on="$listeners"
  >
    <a
      slot="transferNo"
      slot-scope="text, record"
      @click="$emit('number-click', record)"
    >
      {{ text }}
    </a>
    <span slot="handleUserName" slot-scope="text, record">
      {{ fnSolt(text, record) }}
    </span>
  </p-table>
</template>

<script>
export default {
  data() {
    return {};
  },
  computed: {
    nodeOptions() {
      return (
        this.$store.state.dictionary.dict['business_transfer_process_node'] ||
        {}
      );
    },
    stateOptions() {
      return (
        this.$store.state.dictionary.dict['business_transfer_process_status'] ||
        {}
      );
    },
    orgOptions() {
      return this.$store.getters.getOrg({
        code: 'ltcsmsizebu',
      });
    },
    columns() {
      const columns = [
        {
          align: 'center',
          title: '序号',
          width: 60,
          customRender(t, r, index) {
            return parseInt(index) + 1;
          },
        },
        {
          align: 'center',
          title: '转派单号',
          dataIndex: 'transferNo',
          ellipsis: true,
          width: 150,
          sorter: true,
          scopedSlots: { customRender: 'transferNo' },
        },
        {
          align: 'center',
          title: '商机编号',
          dataIndex: 'opportunityNo',
          ellipsis: true,
          width: 150,
          sorter: true,
        },
        {
          align: 'center',
          title: '商机名称',
          dataIndex: 'opportunityName',
          width: 160,
          ellipsis: true,
          sorter: true,
        },
        {
          align: 'center',
          title: '客户简称',
          dataIndex: 'customerShortName',
          width: 160,
          ellipsis: true,
          sorter: true,
        },
        {
          align: 'center',
          title: '当前状态',
          dataIndex: 'currStatus',
          customRender: text => this.stateOptions[text],
          width: 160,
          sorter: true,
          ellipsis: true,
        },
        {
          align: 'center',
          title: '当前节点',
          dataIndex: 'nodeCode',
          width: 160,
          sorter: true,
          ellipsis: true,
          customRender: text => this.nodeOptions[text],
        },
        {
          align: 'center',
          title: '当前处理人',
          dataIndex: 'handleUserName',
          width: 160,
          sorter: true,
          ellipsis: true,
          scopedSlots: { customRender: 'handleUserName' },
        },
        {
          align: 'center',
          title: '销售组织',
          dataIndex: 'salesOrgCode',
          width: 160,
          sorter: true,
          ellipsis: true,
          customRender: text => this.orgOptions[text],
        },
        {
          align: 'center',
          title: '销售',
          dataIndex: 'salesName',
          width: 160,
          sorter: true,
          ellipsis: true,
        },
        {
          align: 'center',
          title: 'PM',
          dataIndex: 'pmName',
          width: 160,
          sorter: true,
          ellipsis: true,
        },
        {
          align: 'center',
          title: '创建人',
          dataIndex: 'createUserName',
          width: 160,
          sorter: true,
          ellipsis: true,
        },
        {
          align: 'center',
          title: '创建时间',
          dataIndex: 'createTime',
          width: 160,
          sorter: true,
          ellipsis: true,
        },
      ];
      return columns;
    },
  },

  methods: {
    fnSolt(txt, val) {
      if (
        val.handleUserName === null ||
        val.currStatus === '4' ||
        val.currStatus === '3'
      ) {
        return '-';
      }
      return val.handleUserName;
    },
  },
};
</script>

<style lang="less" scoped>
.table-list-container {
  margin-top: 20px;
}
</style>
